package hairdressing;

import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.*;

public class Hairdresser extends Thread
{
    int ID;
    Hairdresser(int n)
    {
        ID = n;
    }
    
    
    
    @Override
    public void run()
    {
        while (true)
        {
            try
            {
                Hairdressers.Cust_read.acquire();
                Hairdressers.coord.acquire();
                ToCut();
                Hairdressers.finished[Hairdressers.waiting_list.pollFirst()-1].release();
                Hairdressers.coord.release();
                
            }
            catch (InterruptedException ex)
            {
                Logger.getLogger(Hairdresser.class.getName()).log(Level.SEVERE, null, ex);
            }
        }     
    }
    
    public void ToCut() throws InterruptedException 
    {
        Random randomizer = new Random();
        int t = randomizer.nextInt(10);
        Output.Cut(ID, Hairdressers.waiting_list.getFirst(), t);
	sleep(t);   
    }    

}
